{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c6ff9033",
   "metadata": {},
   "source": [
    "## numpy函数-布尔函数\n",
    "\n",
    "numpy.any:判断是否存在真元素(任一个元素)，只要有一个为ture函数返回ture\n",
    "numpy.all:判断所有的元素为真，结果返回真值ture"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6e8b8744",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6eb6d8fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6, 8, 3, 1, 7],\n",
       "       [8, 4, 6, 1, 7],\n",
       "       [4, 6, 3, 4, 2]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = np.random.randint(0,9,size=(3,5))\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b8546f8f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.any(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e687eabc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.all(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c4c9cfac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5, 6, 7, 8])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2=np.arange(0,9)\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6d83e5c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.any(d2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e0a1bbb6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#ture和false的判断标准同python的基本标准:即空字符串、0、None都为flase.\n",
    "np.all(d2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b6424ea0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#结合逻辑判断语句进行判断\n",
    "#逻辑语句返回逻辑数组，之后使用函数得出结果比较快速\n",
    "np.any(d>3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "feb78378",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ True,  True, False, False,  True],\n",
       "       [ True,  True,  True, False,  True],\n",
       "       [ True,  True, False,  True, False]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d>3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "456e401e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(d>3).any()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
